{% extends "base.html" %}
{% load match %}
{% load pretty_user %}
{% load percentage %}

{% block additional_title %}
{{ user_object.user.first_name }} {{ user_object.user.last_name }}
{% endblock %}

{% block content %}

	<center><h1>{{ user_object|pretty_user:0 }}</h1></center>
	
	<br/>
	<!-- ovaj div ce stoji dok se nesto ne uradi po pitanju layout-a:) -->
	<center>
		{% if user_object.image %}
			<img src="{{ user_object.image.url }}" height="200" alt="{{ user_object.user.username }}"></img>
		{% else %}
			<img src="{{ settings.MEDIA_URL }}images/users/unknown.jpg" width="200" height="200" alt="unknown"></img>
		{% endif %}
	</center>
	<div id="userdata">
		<center><h2>Opšti podaci</h2></center>
		<table class="tablesorter">
			<thead>
				<tr>
					<th/>
					<th>
						Šah
					</th>
					<th>
						Stoni fudbal
					</th>
					<th>
						Fudbal
					</th>
					<th>
						Basket
					</th>
				</tr>
			</thead>
			<tbody>
				<tr>
					<td>Mesto na tabeli:</td>
					<td>{{ chess.standing }}.</td>
					<td>{{ tf.standing }}.</td>
					<td>{{ football.standing }}.</td>
					<td>{{ basket.standing }}.</td>
				</tr>
				<tr>
					<td>Poena:</td>
					<td>{{ user_object.chess_points }}</td>
					<td>{{ user_object.tf_points }}</td>
					<td>{{ user_object.football_points }}</td>
					<td>{{ user_object.basket_points }}</td>
				</tr>
				<tr>
					<td>Maksimalno poena:</td>
					<td>{{ chess.max_points_log.0 }} ({{ chess.max_points_log.1|date }} {{ chess.max_points_log.1|time }})</td>
					<td>{{ tf.max_points_log.0 }} ({{ tf.max_points_log.1|date }} {{ tf.max_points_log.1|time }})</td>
					<td>{{ football.max_points_log.0 }} ({{ football.max_points_log.1|date }} {{ football.max_points_log.1|time }})</td>
					<td>{{ basket.max_points_log.0 }} ({{ basket.max_points_log.1|date }} {{ basket.max_points_log.1|time }})</td>
				</tr>
				<tr>
					<td>Minimalno poena:</td>
					<td>{{ chess.min_points_log.0 }} ({{ chess.min_points_log.1|date }} {{ chess.min_points_log.1|time }})</td>
					<td>{{ tf.min_points_log.0 }} ({{ tf.min_points_log.1|date }} {{ tf.min_points_log.1|time }})</td>
					<td>{{ football.min_points_log.0 }} ({{ football.min_points_log.1|date }} {{ football.min_points_log.1|time }})</td>
					<td>{{ basket.min_points_log.0 }} ({{ basket.min_points_log.1|date }} {{ basket.min_points_log.1|time }})</td>
				</tr>
				<tr>
					<td>Mečeva odigrano:</td>
					<td>{{ chess.matches_played }}</td>
					<td>{{ tf.matches_played }}</td>
					<td>{{ football.matches_played }}</td>
					<td>{{ basket.matches_played }}</td>
				</tr>
				<tr>
					<td>Dobijenih mečeva:</td>
					<td>{{ chess.matches_won }} ({{ chess.matches_won|percentage:chess.matches_played }})</td>
					<td>{{ tf.matches_won }} ({{ tf.matches_won|percentage:tf.matches_played }})</td>
					<td>{{ football.matches_won }} ({{ football.matches_won|percentage:football.matches_played }})</td>
					<td>{{ basket.matches_won }} ({{ basket.matches_won|percentage:basket.matches_played }})</td>
				</tr>
				<tr>
					<td>Nerešenih mečeva:</td>
					<td>{{ chess.matches_draw }} ({{ chess.matches_draw|percentage:chess.matches_played }})</td>
					<td>/</td>
					<td>{{ football.matches_draw }} ({{ football.matches_draw|percentage:football.matches_played }})</td>
					<td>/</td>
				</tr>
				<tr>
					<td>Izgubljenih mečeva:</td>
					<td>{{ chess.matches_lost }} ({{ chess.matches_lost|percentage:chess.matches_played }})</td>
					<td>{{ tf.matches_lost }} ({{ tf.matches_lost|percentage:tf.matches_played }})</td>
					<td>{{ football.matches_lost }} ({{ football.matches_lost|percentage:football.matches_played }})</td>
					<td>{{ basket.matches_lost }} ({{ basket.matches_lost|percentage:basket.matches_played }})</td>
				</tr>
				<tr>
					<td>Poslednji put igrao:</td>
					<td>
						{% if chess.last_match.date_played %}
							{{ chess.last_match.date_played|date }} {{ chess.last_match.date_played|time }}
						{% else %}
							Nikad
						{% endif %}
					</td>
					<td>
						{% if tf.last_match.date_played %}
							{{ tf.last_match.date_played|date }} {{ tf.last_match.date_played|time }}
						{% else %}
							Nikad
						{% endif %}
					</td>
					<td>
						{% if football.last_match.date_played %}
							{{ football.last_match.date_played|date }} {{ football.last_match.date_played|time }}
						{% else %}
							Nikad
						{% endif %}
					</td>
					<td>
						{% if basket.last_match.date_played %}
							{{ basket.last_match.date_played|date }} {{ basket.last_match.date_played|time }}
						{% else %}
							Nikad
						{% endif %}
					</td>
				</tr>
				<tr>
					<td>Najčešći saigrači:</td>
					<td>/</td>
					<td>
						{% if tf.teammates.0 %}
						<table>
							<tr>
								<td>
									{% for user in tf.teammates %}
									{{ user.0|pretty_user }}
									<br/>
									{% endfor %}
								</td>
								<td>({{ tf.teammates.0.1 }})</td>
							</tr>
						</table>
						{% else %}
						/
						{% endif %}
					</td>
					<td>
						{% if football.teammates.0 %}
						<table>
							<tr>
								<td>
									{% for user in football.teammates %}
									{{ user.0|pretty_user }}
									<br/>
									{% endfor %}
								</td>
								<td>({{ football.teammates.0.1 }})</td>
							</tr>
						</table>
						{% else %}
						/
						{% endif %}
					</td>
					<td>
						{% if basket.teammates.0 %}
						<table>
							<tr>
								<td>
									{% for user in basket.teammates %}
									{{ user.0|pretty_user }}
									<br/>
									{% endfor %}
								</td>
								<td>({{ basket.teammates.0.1 }})</td>
							</tr>
						</table>
						{% else %}
						/
						{% endif %}
					</td>
				</tr>
				<tr>
					<td>Najčešći protivnici:</td>
					<td>/</td>
					<td>
						{% if tf.opponents.0 %}
						<table>
							<tr>
								<td>
									{% for user in tf.opponents %}
									{{ user.0|pretty_user }}
									<br/>
									{% endfor %}
								</td>
							<td>({{ tf.opponents.0.1 }})</td>
							</tr>
						</table>
						{% else %}
						/
						{% endif %}
					</td>
					<td>
						{% if football.opponents.0 %}
						<table>
							<tr>
								<td>
									{% for user in football.opponents %}
									{{ user.0|pretty_user }}
									<br/>
									{% endfor %}
								</td>
							<td>({{ football.opponents.0.1 }})</td>
							</tr>
						</table>
						{% else %}
						/
						{% endif %}
					</td>
					<td>
						{% if basket.opponents.0 %}
						<table>
							<tr>
								<td>
									{% for user in basket.opponents %}
									{{ user.0|pretty_user }}
									<br/>
									{% endfor %}
								</td>
							<td>({{ basket.opponents.0.1 }})</td>
							</tr>
						</table>
						{% else %}
						/
						{% endif %}
					</td>
				</tr>
			</tbody>
		</table>
	</div>

	<div>
		<center><h2>Kretanje poena</h2></center>
		<img src="/mdcs/user/{{ user_object.id }}/points_timeline.png" alt="timeline"></img>
	</div>
	<br/>
	<br/>
	
	<div id="pointschange">
		<center><h2>Poslednji odigrani mečevi</h2></center>
		<br/>
		{% if point_logs %}
		<table class="tablesorter">
			<thead>
				<tr>
					<th>Sport</th>
					<th>Igrači</th>
					<th>Rezultat</th>
					<th>Datum</th>
					<th>Promena bodova</th>
					{% if perms.mdcsapp.delete_match %}
	    			<th>Akcije</th>
	    			{% endif %}
	    		</tr>
			</thead>
			<tbody>
			{% for point_log in point_logs %}
				<tr>
					<td>
					{% if point_log.0.match.game_type == 1 %}
					Šah
					{% elif point_log.0.match.game_type == 2 %}
					Stoni fudbal
					{% elif point_log.0.match.game_type == 3 %}
					Fudbal
					{% elif point_log.0.match.game_type == 4 %}
					Basket
					{% else %}
					{% endif %}
					</td>
					<td>{{ point_log.0.match|match }}</td>
					<td>
	            	{% if point_log.0.match.game_type == 1 and point_log.0.match.result == "0:0" %}
	            	½ : ½
	            	{% else %} 
	            	{{ point_log.0.match.result }}
	            	{% endif %}
					</td>
					<td>{{ point_log.0.match.date_played|date }} {{ point_log.0.match.date_played|time }}</td>
					{% ifequal forloop.counter 1 %}
						{% if point_log.0.match.game_type == 1 %}
							<td>{{ point_log.0.points }} &rarr; {{ user_object.chess_points }}</td>
						{% elif point_log.0.match.game_type == 2 %}
							<td>{{ point_log.0.points }} &rarr; {{ user_object.tf_points }}</td>
						{% elif point_log.0.match.game_type == 3 %}
							<td>{{ point_log.0.points }} &rarr; {{ user_object.football_points }}</td>
						{% elif point_log.0.match.game_type == 4 %}
							<td>{{ point_log.0.points }} &rarr; {{ user_object.basket_points }}</td>
						{% else %}
						{% endif %}
					{% else %}
						<td>{{ point_log.0.points }} &rarr; {{ point_log.1.points }}</td>
					{% endifequal %}
					{% if perms.mdcsapp.delete_match %}
	    			<td><a href="/mdcs/match/undo/{{ point_log.0.match.id }}/">Poništi meč</a></td>
	    			{% endif %}
				</tr>
			{% endfor %}
			</tbody>
		</table>
		{% else %}
		Nema nijednog odigranog meča
		{% endif %}
	</div>
{% endblock %}
